$("#update-charging-close").click(function () {
    clearInfo();
    $('#updateCharging').modal('hide')
});
$("#chargingFebsNotice-close").click(function () {
    clearInfo();
    $('#chargingFebsNotice').modal('hide')
});

function clearInfo() {
    $("#update-charging-id").val("");
    $("#update-charging-paymentChannels").val("");
    $("#update-charging-complaintChannels").val("");
    $("#update-charging-acceptanceTime").val("");
    $("#update-charging-processingResults").val("");
    $("#update-charging-complaintType").val("");
    $("#update-charging-contactInformation").val("");
    $("#update-charging-registrar").val("");
    $("#update-charging-handler").val("");
    $("#update_charging_contentsComplaints").val("");
    $("#update_charging_processingTime").val("");
    $("#update_charging_processing").val("");
    $("#update-charging-remakes").val("");
}
function load_data(x){
    update_charging_paymentChannels();
    update_charging_complaintChannels();
    update_charging_complaintType();
    update_charging_dutyDetermine();
    update_charging_processing()
    if(x === null || x === ''){
        $MB.n_danger("系统异常，请重新操作");
        $('#updateCharging').modal('hide')
    }
    var obj = new Object();
    obj.id = x;
    $.post(ctx+"charging/getChargingId",obj,function(r){
        if (r.code !== 0) {
            $MB.n_danger(r.msg);
            $('#updateCharging').modal('hide')
            return;
        }
        $("#update_charging_id").val(r.data.id);
        $("#update_charging_paymentChannels option:selected").text(r.data.paymentChannels);
        $("#update_charging_complaintChannels option:selected").text(r.data.complaintChannels);
        $("#update_charging_complaintType option:selected").text(r.data.complaintType);
        $("#update_charging_processing option:selected").text(r.data.processing);
        $("#update_charging_acceptanceTime").val(r.data.acceptanceTime);
        $("#update_charging_processingResults").val(r.data.processingResults);
        $("#update_charging_contactInformation").val(r.data.contactInformation);
        $("#update_charging_registrar").val(r.data.registrar);
        $("#update_charging_handler").val(r.data.handler);
        //$("#update_submission_busCompany").val(r.data.busCompany);
        $("#update_charging_contentsComplaints").val(r.data.contentsComplaints);
        $("#update_charging_remakes").val(r.data.remakes);
        $("#update_charging_processingTime").val(r.data.processingTime);
        $("#update_charging_pic").attr("src",r.data.picName);
    });
}

function chargingFebsNotice(x){

    if(x === null || x === ''){
        $MB.n_danger("系统异常，请重新操作");
        $('#update-charging').modal('hide')
    }
    var obj = new Object();
    obj.id = x;
    $.post(ctx+"charging/getChargingId",obj,function(r){
        if (r.code !== 0) {
            $MB.n_danger(r.msg);
            $('#update-charging').modal('hide')
            return;
        }
        $("#charging_id").val(r.data.id);
        $("#charging_phone").val(r.data.contactInformation);
    });
}

$(function () {

    $("#update-charging-save").click(function () {
        var id = $('#update_charging_id').val();
        var paymentChannels =$('#update_charging_paymentChannels option:selected').text();
        var complaintChannels =$('#update_charging_complaintChannels option:selected').text();
        if(processing==="已处理"){
            if(complaintChannels === null || complaintChannels ===""){
                $MB.n_danger("请输入投诉渠道！");
                $('#noCard').modal('hide')
                return;
            }
        }
        var processing =$('#update_charging_processing option:selected').text();

        var contentsComplaints = $("#update_charging_contentsComplaints").val();
        if(processing==="已处理"){
                    if(contentsComplaints === null || contentsComplaints ===""){
                        $MB.n_danger("请输入投诉内容！");
                        $('#noCard').modal('hide')
                        return;
                    }
        }

        var contactInformation = $("#update_charging_contactInformation").val();
        if(processing==="已处理"){
            if(contactInformation === null || contactInformation ===""){
            $MB.n_danger("请输入联系方式！");
            $('#noCard').modal('hide')
            return;
            }
        }

        var acceptanceTime = $("#update_charging_acceptanceTime").val();
        var processingResults = $("#update_charging_processingResults").val();
        if(processing==="已处理"){
            if(processingResults === null || processingResults ===""){
                $MB.n_danger("请输入处理结果！");
                $('#noCard').modal('hide')
                return;
            }
        }

        var registrar = $("#update_charging_registrar").val();
        if(processing==="已处理"){
            if(registrar === null || registrar ===""){
            $MB.n_danger("请输入登记人！");
            $('#noCard').modal('hide')
            return;
        }
        }

        var handler = $("#update_charging_handler").val();
        if(processing==="已处理"){
            if(handler === null || handler ===""){
            $MB.n_danger("请输入处理人！");
            $('#noCard').modal('hide')
            return;
        }
        }

        var complaintType =$('#update_charging_complaintType option:selected').text();

        if(processing==="已处理"){
            if(complaintType === null || complaintType ===""){
                $MB.n_danger("请输入投诉类别！");
                $('#noCard').modal('hide')
                return;
            }

        }
        var dutyDetermine =$('#update_charging_dutyDetermine option:selected').text();

        var remakes = $("#update_charging_remakes").val();

        var processingTime = $("#update_charging_processingTime").val();

/*        if(processing==="已处理"){
            if(processingTime === null || processingTime ===""){
                $MB.n_danger("请输入处理时间！");
                $('#noCard').modal('hide')
                return;
            }
        }*/


/*        if(processing==="已处理"){
            Date.prototype.Format = function (fmt) { // author: meizz
                var o = {
                    "M+": this.getMonth() + 1, // 月份
                    "d+": this.getDate(), // 日
                    "h+": this.getHours(), // 小时
                    "m+": this.getMinutes(), // 分
                    "s+": this.getSeconds(), // 秒
                    "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
                    "S": this.getMilliseconds() // 毫秒
                };
                if (/(y+)/.test(fmt))
                    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;
            }
            var time2 = new Date().Format("yyyy-MM-dd hh:mm:ss");
            console.log(time2)
        }*/


        if(processing==="待处理" || processing ==="未处理"){
            if(processingTime !== ""){
                $MB.n_danger("投诉信息"+processing+"，请不要输入处理时间！");
                $('#noCard').modal('hide')
                return;
            }
        }
        var picFiles = $("#addUpdateChargingPic")[0].files;
        var pic ;
        if(picFiles && picFiles.length > 0){
            pic = picFiles[0]
        }

        var par = new FormData();
        par.append("id", id);
        par.append("paymentChannels", paymentChannels);
        par.append("complaintChannels", complaintChannels);
        par.append("acceptanceTime", acceptanceTime);
        par.append("processingResults", processingResults);
        par.append("complaintType", complaintType);
        par.append("dutyDetermine", dutyDetermine);
        par.append("remakes", remakes);
        par.append("contactInformation", contactInformation);
        par.append("registrar", registrar);
        par.append("handler", handler);
        par.append("contentsComplaints", contentsComplaints);
        par.append("processing", processing);
        /*par.append("processingTime", processingTime);*/
        par.append("pic", pic);
/*        var par = new Object()
        par.id = id;
        par.paymentChannels = paymentChannels;
        par.complaintChannels = complaintChannels;
        par.acceptanceTime = acceptanceTime;
        par.processingResults = processingResults;
        par.complaintType = complaintType;
        par.dutyDetermine = dutyDetermine;
        par.remakes = remakes;
        par.contactInformation = contactInformation;
        par.registrar = registrar;
        par.handler = handler;
        par.contentsComplaints = contentsComplaints;
        par.processing = processing;
        par.processingTime = processingTime;*/


        $.ajax({
            url :  ctx+"charging/updateCharging",
            type : 'POST',
            async : false,
            data : par,
            // 告诉jQuery不要去处理发送的数据
            processData : false,
            // 告诉jQuery不要去设置Content-Type请求头
            contentType : false,
            beforeSend:function(){
                console.log("正在进行，请稍候");
            },
            success : function(r) {
                if (r.code !== 0) {
                    $MB.n_danger(r.msg);
                    $('#updateCharging').modal('hide')
                    return;
                }else{
                    $MB.n_success("投诉信息已修改！");
                    // print(r);
                    $('#updateCharging').modal('hide')
                    console.log(r)
                    return;
                }
            }
        });



/*        $.post(ctx+"charging/updateCharging",par,function (r) {
            if (r.code !== 0) {
                $MB.n_danger(r.msg);
                $('#updateCharging').modal('hide')
                return;
            }else{
                $MB.n_success("充电桩投诉信息已修改！");
                // print(r);
                $('#updateCharging').modal('hide')
                console.log(r)
                return;
            }
        });*/

    });

});

$(function () {

    $("#chargingFebsNotice-save").click(function () {


        var id = $("#charging_id").val();

        if(id === null || id ===""){
            $MB.n_danger("请输入投诉编号！");
            $('#chargingFebsNotice').modal('hide')
            return;
        }

        var phone = $("#charging_phone").val();

        if(phone === null || phone ===""){
            $MB.n_danger("请输入发送电话号码！");
            $('#chargingFebsNotice').modal('hide')
            return;
        }

        var value = $("#charging_value").val();

        if(value === null || value ===""){
            $MB.n_danger("请输入发送内容！");
            $('#chargingFebsNotice').modal('hide')
            return;
        }



        var par = new Object()
        par.id = id;
        par.phone = phone;
        par.value = value;


        $.post(ctx+"charging/chargingFebsNotice",par,function (r) {
            if (r.code !== 0) {
                $MB.n_danger(r.msg);
                $('#chargingFebsNotice').modal('hide')
                return;
            }else{
                $MB.n_success("短信发送成功！");
                // print(r);
                $('#chargingFebsNotice').modal('hide')
                console.log(r)
                return;
            }
        });
    });

});


$("#updateCharging .btn-close").click(function () {
    closeModal();
});
function closeModal() {
    $MB.closeAndRestModal("updateCharging");
    clearInfo();
}

//初始化修改页面下拉选，加载受理支付渠道下拉选
function update_charging_paymentChannels() {
    $("#update_charging_paymentChannels").empty();
    $.ajax({
            type:"get",
            dataType:"json",
            contentType:"application/json;charset=utf-8",
            url:ctx+"charging/pullDown?submissionKey=paymentChannels",

            success:function(result){
                $("#update_charging_paymentChannels").append("<option value=\"\" selected=\"selected\" disabled=\"disabled\"  style='display: none'></option>");
                $.each(result,function(index,value){

                        $("#update_charging_paymentChannels").append("<option value='"+value.id+"'>"+value.submissionValue+"</option>");

                })
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            },
            async:false             //false表示同步
        }

    );
}

//初始化修改页面下拉选，加载投诉渠道下拉选
function update_charging_complaintChannels() {
    $("#update_charging_complaintChannels").empty();
    $.ajax({
            type:"get",
            dataType:"json",
            contentType:"application/json;charset=utf-8",
            url:ctx+"charging/pullDown?submissionKey=complaintChannels",

            success:function(result){
                $("#update_charging_complaintChannels").append("<option value=\"\" selected=\"selected\" disabled=\"disabled\"  style='display: none'></option>");
                $.each(result,function(index,value){

                    $("#update_charging_complaintChannels").append("<option value='"+value.id+"'>"+value.submissionValue+"</option>");

                })

            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            },
            async:false             //false表示同步
        }

    );
}


//初始化修改页面下拉选，加载投诉类别下拉选
function update_charging_complaintType() {
    $("#update_charging_complaintType").empty();
    $.ajax({
            type:"get",
            dataType:"json",
            contentType:"application/json;charset=utf-8",
            url:ctx+"charging/pullDown?submissionKey=complaintType",

            success:function(result){
                $("#update_charging_complaintType").append("<option value=\"\" selected=\"selected\" disabled=\"disabled\"  style='display: none'></option>");
                $.each(result,function(index,value){

                    $("#update_charging_complaintType").append("<option value='"+value.id+"'>"+value.submissionValue+"</option>");

                })
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            },
            async:false             //false表示同步
        }

    );
}

//初始化修改页面下拉选，加载责任判定下拉选
function update_charging_dutyDetermine() {
    $("#update_charging_dutyDetermine").empty();
    $.ajax({
            type:"get",
            dataType:"json",
            contentType:"application/json;charset=utf-8",
            url:ctx+"charging/pullDown?submissionKey=dutyDetermine",

            success:function(result){
                $("#update_charging_dutyDetermine").append("<option value=\"\" selected=\"selected\" disabled=\"disabled\"  style='display: none'></option>");
                $.each(result,function(index,value){

                    $("#update_charging_dutyDetermine").append("<option value='"+value.id+"'>"+value.submissionValue+"</option>");

                })
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            },
            async:false             //false表示同步
        }

    );
}

//初始化修改页面下拉选，加载处理状态下拉选
function update_charging_processing() {
    $("#update_charging_processing").empty();
    $.ajax({
            type:"get",
            dataType:"json",
            contentType:"application/json;charset=utf-8",
            url:ctx+"charging/pullDown?submissionKey=processing",

            success:function(result){
                $("#update_charging_processing").append("<option value=\"\" selected=\"selected\" disabled=\"disabled\"  style='display: none'></option>");
                $.each(result,function(index,value){

                    $("#update_charging_processing").append("<option value='"+value.id+"'>"+value.submissionValue+"</option>");

                })
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            },
            async:false             //false表示同步
        }

    );
}